/**
 * @Author：ming
 * @Date：2023/9/26 12:37 PM
 * @Filename：Lc202
 */

import java.util.HashMap;

/**
 * @author ming
 */
public class Lc202 {
    public boolean isHappy(int n) {
        int slow = n;
        int fast = n;
        do{
            slow = getHappy(slow);
            fast = getHappy(fast);
            fast = getHappy(fast);

        }while (fast!=slow);
        return slow==1;
    }

    public static int getHappy(int n){
        int sum =0;
       while (n>0){
           int t = n%10;
           sum += t*t;
           n = n/10;
       }
       return sum;
    }
}
